import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const router = new Router({
    mode: 'history',
    routes: [
        //默认
        {
            path: '/',
            redirect: '/index',
        },
        {
            path: '/newdetails',
            name: 'NewDetails',
            component: () => import('../views/index/NewDetails')
        },
        //主页
        {
            path: '/index',
            redirect: '/index/new_list',
            component: () => import('../views/index/Index'),
            name: 'Index',
            children: [
                //最新列表
                {
                    path: 'new_list',
                    component: () => import('../views/index/NewList'),
                    name: 'NewList',
                    children: [

                    ]

                },
                //最热列表
                {
                    path: 'hot_list',
                    component: () => import('../views/index/HotList'),
                    name: 'HotList'
                },
                //关注列表
                {
                    path: 'follow_list',
                    component: () => import('../views/index/FollowList'),
                    name: 'FollowList'
                }
            ]
        },
        //发布文章
        {
            path: '/publish',
            component: () => import('../views/article/Publish'),
            name: 'Publish'
        },
        //登录
        {
            path: '/login',
            component: () => import('../views/Login'),
            name: 'Login',
        },
        //注册
        {
            path: '/register',
            name: 'Register',
            component: () => import('../views/Register')

        },
        //等你来答(问题列表)
        {
            path: '/issues_list',
            component: () => import('../views/answer/IssuesList'),
            name: 'IssuesList'
        },
        //个人主页
        {
            path: '/personal',
            // redirect: '/personal/art_list',
            component: () => import('../views/homepage/Personal'),
            name: 'Personal',
            children: [
                //文章列表
                {
                    path: 'art_list',
                    component: () => import('../views/homepage/ArtList'),
                    name: 'ArtList'
                },
                //  收藏列表
                {
                    path: 'collect_list',
                    component: () => import('../views/homepage/CollectList'),
                    name: 'CollectList'
                },
                //粉丝列表
                {
                    path: 'fans_list',
                    component: () => import('../views/homepage/FansList'),
                    name: 'FansList'
                },
                //关注列表
                {
                    path: 'follow_listUser',
                    component: () => import('../views/homepage/FollowList'),
                    name: 'FollowListUser'
                },

            ]
        },
        {
            path: '/edit',
            component: () => import('../views/homepage/Edit'),
            name: 'Edit'
        }
    ],

})

// router.beforeEach((to, from, next) => {
//     const token = localStorage.getItem('token');
//     //1.放行的前提是：
//     //1) token 不为空 
//     //2) 或者是登录页面
//     if ((token != null && token != '') || to.path == '/login') {
//         //这里已经放行
//         next()
//     } else {
//         alert("您无权访问");
//         next('/login')
//     }
// })

export default router